import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/userInfo',
    children: [
      {
        path: 'userInfo',
        name: 'UserInfo',
        component: () => import('@/views/user/userInfo'),
        meta: { title: '个人信息', icon: 'user' }
      },
      {
        path: 'userManage',
        name: 'UserManage',
        component: () => import('@/views/user/userManage'),
        meta: { title: '用户管理', icon: 'user' }
      },
      {
        path: 'addUser',
        name: 'AddUser',
        component: () => import('@/views/user/addOrEdit'),
        meta: { title: '新增用户' }
      },
      {
        path: 'editUser/:id',
        name: 'EditUser',
        component: () => import('@/views/user/addOrEdit'),
        meta: { title: '编辑用户' }
      }
    ]
  },

  {
    path: '/wq',
    component: Layout,
    children: [
      {
        path: 'ph',
        name: 'PH',
        component: () => import('@/views/wq/ph'),
        meta: { title: 'PH', icon: 'user' }
      },
      {
        path: 'an',
        name: 'AN',
        component: () => import('@/views/wq/an'),
        meta: { title: '氨氮', icon: 'user' }
      },
      {
        path: 'o2',
        name: 'O2',
        component: () => import('@/views/wq/o2'),
        meta: { title: '溶氧', icon: 'user' }
      },
      {
        path: 'nitrite',
        name: 'Nitrite',
        component: () => import('@/views/wq/nitrite'),
        meta: { title: '亚硝酸盐', icon: 'user' }
      }
    ]
  },

  {
    path: '/science',
    component: Layout,
    redirect: '/science/index',
    children: [
      {
        path: 'index',
        name: 'Science',
        component: () => import('@/views/science'),
        meta: { title: '历史分析', icon: 'user' }
      },
      {
        path: 'test',
        name: 'ScienceTest',
        component: () => import('@/views/science/test.vue'),
        meta: { title: '水质自测', icon: 'user' }
      }
    ]
  },

  {
    path: '/ai',
    component: Layout,
    redirect: '/ai/index',
    children: [
      {
        path: 'index',
        name: 'AI',
        component: () => import('@/views/ai'),
        meta: { title: 'AI 诊疗', icon: 'user' }
      }
    ]
  },

  {
    path: '/good',
    component: Layout,
    redirect: '/good/list',
    children: [
      {
        path: 'list',
        name: 'GoodList',
        component: () => import('@/views/good'),
        meta: { title: '商品列表' }
      },
      {
        path: 'addGood',
        name: 'AddGood',
        component: () => import('@/views/good/addOrEdit'),
        meta: { title: '新增商品' }
      },
      {
        path: 'editGood/:id',
        name: 'EditGood',
        component: () => import('@/views/good/addOrEdit'),
        meta: { title: '编辑商品' }
      }
    ]
  },

  {
    path: '/announcement',
    component: Layout,
    redirect: '/announcement/list',
    children: [
      {
        path: 'list',
        name: 'AnnouncementList',
        component: () => import('@/views/announcement'),
        meta: { title: '公告列表' }
      },
      {
        path: 'addAnnouncement',
        name: 'AddAnnouncement',
        component: () => import('@/views/announcement/addOrEdit'),
        meta: { title: '新增公告' }
      },
      {
        path: 'editAnnouncement/:id',
        name: 'EditAnnouncement',
        component: () => import('@/views/announcement/addOrEdit'),
        meta: { title: '编辑公告' }
      },
      {
        path: 'detailAnnouncement/:id',
        name: 'DetailAnnouncement',
        component: () => import('@/views/announcement/view'),
        meta: { title: '查看公告' }
      }

    ]
  },

  {
    path: '/feedback',
    component: Layout,
    redirect: '/feedback/list',
    children: [
      {
        path: 'list',
        name: 'FeedbackList',
        component: () => import('@/views/feedback'),
        meta: { title: '反馈列表' }
      },
      {
        path: 'addFeedback',
        name: 'AddFeedback',
        component: () => import('@/views/feedback/addOrEdit'),
        meta: { title: '新增反馈' }
      },
      {
        path: 'editFeedback/:id',
        name: 'EditFeedback',
        component: () => import('@/views/feedback/addOrEdit'),
        meta: { title: '编辑反馈' }
      },
      {
        path: 'detailFeedback/:id',
        name: 'DetailFeedback',
        component: () => import('@/views/feedback/view'),
        meta: { title: '反馈详情' }
      }
    ]
  },


  //ai诊疗
  {
    path: '/ai',
    component: Layout,
    redirect: '/ai/list',
    children: [
      {
        path: 'list',
        name: 'AiList',
        component: () => import('@/views/ai'),
        meta: { title: 'AI诊疗列表' }
      },
      {
        path: 'newAi',
        name: 'NewAi',
        component: () => import('@/views/ai/view'),
        meta: { title: '新AI诊疗' }
      },
      {
        path: 'detailAi/:id',
        name: 'DetailAi',
        component: () => import('@/views/ai/view'),
        meta: { title: 'AI诊疗详情' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = []

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
